package com.baichen;

import tech.medivh.classpy.classfile.ClassFile;
import tech.medivh.classpy.classfile.ClassFileParser;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;

public class Hotspot {

    private final String mainClass;

    private final BootstrapClassLoader bootstrapClassLoader;

    public Hotspot(String mainClass, String classPathString) {
        this.mainClass = mainClass;
        this.bootstrapClassLoader = new BootstrapClassLoader(Arrays.asList(classPathString.split(File.pathSeparator)));
    }

    public void start() throws Exception {
        ClassFile mainClassFile = bootstrapClassLoader.loadClass(mainClass);
        JvmStack stack = new JvmStack();
        // 现在默认main方法中的args不存在，先不传，TODO
        StackFrame mainFrame = new StackFrame(mainClassFile.getMainMethod(), mainClassFile.getConstantPool());
        Thread thread = new Thread("main", mainFrame,bootstrapClassLoader);
        thread.start();
    }


}
